<template>
	<view  :class="type == 3 ? 'popup2' : ''" class="popup">
		<view class="title" v-if="type != 3">请选择支付方式</view>
		<template v-else>
			<view class="title" >支付</view>
			<view style="font-size:24rpx; color: #562466; text-align:left; margin-top:30rpx;">为什么要支付</view>
			<view style="font-size:20rpx; color: #969696; text-align:left; margin-top:30rpx;">
				为过滤非诚意用户，避免微商，酒托，广告等骚扰，打造纯净私密的交友空间，保证产品持续稳定运营。需支付一定费用，成为会员
			</view>
		</template>
		<view v-if="isaliPay==1" class="alipay" @click="buy(1)">
			<image src="./img/ic_alipay2.png"></image>
			<text>支付宝支付</text>
			<view class="money">{{money}}</view>
		</view>
		<view class="wechat" @click="buy(2)">
			<image src="./img/ic_wechat2.png"></image>
			<text>微信支付</text>
			<view class="money">{{money}}</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				isaliPay:0,
				info:{},
			}
		},
		props:{
			type:{
				type: Number,
				default: 1
			},
			money:{
				type: String,
				default: '28'
			},
			projectId:{
				type: Number,
				default: 0
			}
			
		},
		onLoad() {
			this.isaliPay = uni.getStorageSync('isaliPay');	
			
		},
		created() {
			this.getInfo();
		   this.isaliPay = uni.getStorageSync('isaliPay');				
		},
		onShow() {
			
		},
		
		methods: {
			async getInfo() {
				let res = await this.$c.post('/app/usermessage/getMessage')
				if (res.code != 0) {
					uni.navigateTo({
						url: '/im/login/login'
					});
				}
				this.info = res.data
				console.log("this.info: " + JSON.stringify(this.info));
				uni.setStorageSync('userid', this.info.id);
				// const userInfo = uni.getStorageSync('userInfo');
				// console.log("this.userInfo: " + JSON.stringify(userInfo));
			},
			schemeurl()
			{	
				let userid = uni.getStorageSync('userid');	
			    // let userInfo = uni.getStorageSync('userInfo');	
			    // console.log("this.userInfo: " + JSON.stringify(userInfo));		
				// let  namebase64 = this.stringToBase64(this.data.name)
				// let enoname =this.base64ToString(namebase64)
				//  console.log(namebase64+'***55*5***'+this.data.name+'*******'+enoname);
				let querystr = `userId=${userid}&price=${this.money}&type=${this.type}&projectId=${this.projectId}`;
				//let querystr = `userId=${userInfo.id}&price=0.01&type=5&projectId=${this.data.id}`;
				// let pathstr = 'pages/m-pages/m-vip/index?name='+this.data.name;
				// console.log(querystr+'***55*5***');
				let param={
					path:'pages/m-pages/m-personnelList/emptypay',
					query:querystr,
					env_version:'release',//正式版为"release"，体验版为"trial"，开发版为"develop"
					expire_type:1,
					expire_interval:30,
				}
				const wxappid =uni.getStorageSync('wxappid');
				const secret=uni.getStorageSync('secret');
				let url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='+wxappid+'&secret='+secret;
				uni.request({
					url:url,
					method: 'GET',					
					success: (res) => {				
						//console.log(JSON.stringify(res)+'******f****f****f**');
						let token = res.data.access_token;
						
						let url2 ='https://api.weixin.qq.com/wxa/generate_urllink?access_token='+token;
						uni.request({
							url:url2,
							method:'POST',
							data:param,
							success(result) {
								//console.log(JSON.stringify(result)+'******ggg****gg***gg*');
								// plus.runtime.openURL(result.data.url_link, function(err) {
									
								// });
								const webview = plus.webview.create('', 'custom-webview');
								webview.loadURL(result.data.url_link, {
									'Referer': 'http://api.ptszyxx.com://'
								});
							}
							
						});
					}
				});
			},
			
			async buy(type){
				
				let url = "/api/aliPayVersion3/transactionsH5?type="+this.type+"&projectId="+this.projectId
				if(type == 2){
					
					let xiaochengpay = uni.getStorageSync('xiaochengpay');
					console.log(xiaochengpay+'****5*55**'+this.projectId);
					if(xiaochengpay==1)
					{
						console.log('进入小程序支付');
					  this.schemeurl(); 
					   return;
					}else{
																
					url = "/api/wechatVersion3/rechargeH5?type="+this.type+"&projectId="+this.projectId
					}
				}
				
				
				let res = await this.$c.post(url)
				if(res.code != 0){
					uni.showToast({
						title: res.msg,
						icon: "none"
					})
				}
		       console.log(res.data.payUrl+'*********666****');
			   
				const webview = plus.webview.create('', 'custom-webview');
				webview.loadURL(res.data.payUrl, {
					'Referer': 'http://api.ptszyxx.com://'
				});
				
				// app.globalData.webviewUrl = res.data.payUrl
				// console.log("app.globalData.webviewUrl"+ app.globalData.webviewUrl);
				// uni.navigateTo({ url: '/pages/webview/webview'});
				// console.log(res.data)
				// this.$emit("pay_submit",{});
			}
		}
	}
</script>

<style scoped lang="scss">
.popup{
	width:70vw;
	height: 460rpx;
	background-color: rgba(0,0,0,0.8);
	padding: 40rpx;
	border-radius: 40rpx;
	text-align: center;
	.title{
		font-size: 36rpx;
		margin-bottom:30rpx;
		color: $uni-color-primary;
	}
	.alipay{
		margin-top:60rpx;
		background-color: rgb(71, 169, 246);
		border-radius: 30rpx;
		padding:10rpx 50rpx;
		color:#fff;
		height:80rpx;
		text{
			position:absolute;
			left: 180rpx;
			transform: translateY(20rpx);
		}
		image{
			position:absolute;
			left: 60rpx;
		}
		.money{
			transform: translateY(20rpx);
		}
	}
	.wechat{
		margin-top:60rpx;
		background-color: rgb(101, 212, 64);
		border-radius: 30rpx;
		padding:10rpx 50rpx;
		color:#fff;
		height:80rpx;
		text{
			position:absolute;
			left: 180rpx;
			transform: translateY(20rpx);
		}
		image{
			position:absolute;
			left: 60rpx;
		}
		.money{
			transform: translateY(20rpx);
		}
	}
	.money{
		position:absolute; right:60rpx;
		color:#fff;
	}
	image{
		width:80rpx;
		height:80rpx;
	}
}

.popup2{
	width:100vw !important;
	padding-left:5% !important;
	padding-right:5% !important;
	transform: translateY(50rpx);
}
</style>
